package com.example.demospringmybatisplus.controller;

import io.github.resilience4j.retry.annotation.Retry;
import lombok.extern.slf4j.Slf4j;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * Resilience4j 是一个轻量级的容错库，提供了诸如熔断、重试、限流、超时、隔板等功能
 *
 * @author huahua
 * @DATE 2025/2/16
 **/
@RestController
@Slf4j
public class Resilience4jController {
    @GetMapping("/retry")
    @Retry(name="retryApi",fallbackMethod="fallbackTest")
    public ResponseEntity<String> retryApi() {
        log.info("{}", "retryApi call received");
        String ret = new RestTemplate().getForObject("http://localhost:9000/retry", String.class);
        return new ResponseEntity<>("success", HttpStatus.OK);
    }
}
